/**
 *
 */
import {nanoid} from "nanoid"

const initState = [{id: nanoid(), name: "defaultName", age: "defaultAge"}]

export default function personReducer(preState = initState, action) {
  const {type, data} = action
  switch (type) {
    case "addPerson":
      // preState.unshift(data) // 不能这样写，会导致preState发生变化，reducer必须是纯函数
      return [data, ...preState]
    default:
      return preState
  }
}